﻿using System.Windows.Controls;

namespace FrontDisplay
{
    /// <summary>
    /// Interaction logic for UserPageButton.xaml
    /// </summary>
    public partial class MenuPageButton : UserControl
    {
        private IPlugin _plugin;
        private MenuItem _menuItem;

        public MenuPageButton()
        {
            InitializeComponent();
        }

        public MenuPageButton(IPlugin plugin, ContextMenu contextMenu)
        {
            InitializeComponent();

            _plugin = plugin;

            TitleText.Text = plugin.Title;

            if (plugin.MenuButton != null)
            {
                ContentLabel.Content = plugin.MenuButton;
            }

            Control buttonControl = plugin.PageControl;
            PreviewMouseLeftButtonDown += delegate { Navigation.Navigate(buttonControl); };

            _menuItem = new MenuItem { Header = plugin.Title };
            Control control = plugin.PageControl;
            _menuItem.Click += delegate { Navigation.Navigate(control); };
            contextMenu.Items.Insert(0, _menuItem);
        }

        internal void Update()
        {
            _menuItem.Header = _plugin.Title;
            TitleText.Text = _plugin.Title;
        }
    }
}
